package com.jh3502.helper.function.home;

import android.support.annotation.NonNull;

import com.jh3502.helper.base.BaseCallback;
import com.jh3502.helper.base.BaseJson;
import com.jh3502.helper.base.BasePresenter;
import com.jh3502.helper.base.BaseView;
import com.jh3502.helper.utils.SpHelper;
import com.jh3502.helper.utils.Utils;

import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class HomePresenter extends BasePresenter {
    HomeModel mHomeModel;

    HomeView mHomeView;

    public void setHomeView(HomeView mHomeView) {
        this.mHomeView = mHomeView;
    }


    //  更新
    public void toVersion() {
        mHomeView.showLoadingDialog();
        if (mHomeModel == null) {
            mHomeModel = new HomeModel(mHomeView.getActContext());
        }

        mHomeModel.version(new BaseCallback(mHomeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mHomeView.versionSuccess(Utils.getInstance().jso2map(baseJson.getObj().toString()));
            }
        });
    }

    //  特体
    public void toGetteti() {
        mHomeView.showLoadingDialog();
        if (mHomeModel == null) {
            mHomeModel = new HomeModel(mHomeView.getActContext());
        }

        mHomeModel.getteti(new BaseCallback(mHomeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                SpHelper.getInstance().setSp(baseJson.getObj().toString());
                mHomeView.gettetiSuccess();
            }
        });
    }


    public void toListltrule() {
        mHomeView.showLoadingDialog();
        if (mHomeModel == null) {
            mHomeModel = new HomeModel(mHomeView.getActContext());
        }
        mHomeModel.listltrule(new BaseCallback(mHomeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                Map<String, Object> json = Utils.getInstance().jso2map(baseJson.getObj().toString());
                SpHelper.getInstance().setListltruleMale((String) json.get("male"));
                SpHelper.getInstance().setListltruleFemale((String) json.get("female"));
                mHomeView.listltruleSuccess();
            }
        });
    }


    public void toLtShapeRule() {
        mHomeView.showLoadingDialog();
        if (mHomeModel == null) {
            mHomeModel = new HomeModel(mHomeView.getActContext());
        }
        mHomeModel.ltShapeRule(new BaseCallback(mHomeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                Map<String, Object> json = Utils.getInstance().jso2map(baseJson.getObj().toString());
                SpHelper.getInstance().setLtShapeRuleMale((String) json.get("0"));
                SpHelper.getInstance().setLtShapeRuleFemale((String) json.get("1"));
                mHomeView.ltShapeRuleSuccess();
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface HomeView extends BaseView {

        void gettetiSuccess();

        void listltruleSuccess();

        void ltShapeRuleSuccess();

        void versionSuccess(Map<String, Object> map);
    }
}
